// 这里书写属性相关的API文件
import request from '@/utils/request'
// 引入ts类型
import { CategoryResponseData, AttrResponseData, Attr } from './type'

// 商品属性管理相关接口地址
enum API {
  // 获取一级分类接口地址
  C1_URL = '/admin/product/getCategory1/',
  // 获取二级分类接口地址
  C2_URL = '/admin/product/getCategory2/',
  // 获取三级分类接口地址
  C3_URL = '/admin/product/getCategory3/',
  // 获取分类下已有的属性与属性值
  ATTRINFOLIST_URL = '/admin/product/attrInfoList/',
  // 添加或者修改已有的属性与属性值
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  // 删除属性
  DELETEATTR_URL = '/admin/product/deleteAttr/'
}

// 获取一级分类的接口方法
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL)
// 获取二级分类的接口方法
export const reqC2 = (category1ID: number | string) =>
  request.get<any, CategoryResponseData>(API.C2_URL + category1ID)
// 获取三级分类的接口方法
export const reqC3 = (category2ID: number | string) =>
  request.get<any, CategoryResponseData>(API.C3_URL + category2ID)
// 获取分类下已有的属性与属性值的接口
export const reqAttrInfoList = (
  category1ID: number | string,
  category2ID: number | string,
  category3ID: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.ATTRINFOLIST_URL + `${category1ID}/${category2ID}/${category3ID}`,
  )
// 添加或者修改已有的属性与属性值的接口
export const reqAddOrUpdateAttr = (data: Attr)=>request.post<any, any>(API.ADDORUPDATEATTR_URL, data)
// 删除已有的属性
export const reqDeleteAttr = (attrId: number )=>request.delete<any, any>(API.DELETEATTR_URL+attrId)
